package com.youyoulong.framework.util.service.impl;

import java.util.LinkedHashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.youyoulong.framework.util.SpringContextUtil;
import com.youyoulong.framework.util.beans.JavaBeanResultMap;
import com.youyoulong.framework.util.dao.mapper.FrameDataInterfaceMapper;
import com.youyoulong.framework.util.service.IFrameDataInterfaceService;

/**
 * 执行数据接口的主服务类
 * @author you_lan_yan
 *
 */
@Service("util.main.FrameDataInterfaceService")
public class FrameDataInterfaceMainService implements IFrameDataInterfaceService {
	

	
	
	private String serviceBeanName = "util.[接口类型].FrameDataInterfaceService";

	@Resource(name="util.FrameDataInterfaceMapper")
	private FrameDataInterfaceMapper frameDataInterfaceMapper;
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public Object execute(Map params) throws Exception {
		// TODO Auto-generated method stub
		
		//获取接口相关数据
		JavaBeanResultMap<Object> dataInterface = frameDataInterfaceMapper.getDataInterfaceByDataCode(params.get("dataCode").toString());
		params.put(_dataInterface, dataInterface);		
		dataInterface.putNoCamel(_interfaceDefParams, frameDataInterfaceMapper.getDataInterfaceParamsByDataCode(params.get("dataCode").toString()));
		params.put(_targetDataInterface, frameDataInterfaceMapper.getTagertDataInterfaceByDataCode(dataInterface));
		String serviceName = null;
		if(dataInterface.get("dataExecuteName")==null||dataInterface.get("dataExecuteName").toString().trim().isEmpty()){
			serviceName = serviceBeanName.replace("[接口类型]", dataInterface.get("dataType").toString());
		}else{
			serviceName = dataInterface.get("dataExecuteName").toString();     //如果您想自己定义执行的方法，可以在t_frame_data_interface中指定要执行脚本的NAME
		}
		
		if(!params.containsKey(_queryParams)){
			params.put(_queryParams, new LinkedHashMap());
		}
		
		IFrameDataInterfaceService dataExecuteService = (IFrameDataInterfaceService)SpringContextUtil.getBean(serviceName);
		return dataExecuteService.execute(params);
	}
}
